class Fn {
	getLocalTime (nS) {  //时间戳转换  xx-xx-xx
		// return new Date(parseInt(nS)).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
	   	// return new Date(parseInt(nS)).toLocaleString().replace(/\//g,"-").replace(/[\u4e00-\u9fa5]/g,"");
	   	// return new Date(parseInt(nS)).toLocaleString('chinese',{hour24:true})

	   	var date = new Date();
	    date.setTime(nS);
	    var y = date.getFullYear();
	    var m = date.getMonth() + 1;
	    m = m < 10 ? ('0' + m) : m;
	    var d = date.getDate();
	    d = d < 10 ? ('0' + d) : d;
	    var h = date.getHours();
	    h = h < 10 ? ('0' + h) : h;
	    var minute = date.getMinutes();
	    var second = date.getSeconds();
	    minute = minute < 10 ? ('0' + minute) : minute;
	    second = second < 10 ? ('0' + second) : second;
    	return y + '-' + m + '-' + d
	}

	getLocalTimeNo0 (nS) { 
		var date = new Date();
		if ((nS +'') != 'NaN'){
	    date.setTime(nS);
	    var y = date.getFullYear();
	    var m = date.getMonth() + 1;
			m = m < 10 ? ('0' + m) : m;
	    var d = date.getDate();
		 	d = d < 10 ? ('0' + d) : d;
    	return y + '-' + m + '-' + d
} return "";
		}

	getLocalTimeNo1 (nS) {
		var date = new Date();
	    date.setTime(nS);
	    var y = date.getHours();
	    var m = date.getMinutes();
	    var d = date.getSeconds();
    	return y + ':' + m + ':' + d
	}

	getMonthDay (nS) {  //时间戳转换  xx月xx日
		var date = new Date();
	    date.setTime(nS);
	    var y = date.getFullYear();
	    var m = date.getMonth() + 1;
	    m = m < 10 ? ('0' + m) : m;
	    var d = date.getDate();
	    d = d < 10 ? ('0' + d) : d;
	    var h = date.getHours();
	    h = h < 10 ? ('0' + h) : h;
	    var minute = date.getMinutes();
	    var second = date.getSeconds();
	    minute = minute < 10 ? ('0' + minute) : minute;
	    second = second < 10 ? ('0' + second) : second;
    	// return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    	return parseInt(m) + '月' + parseInt(d) + '日';
	}
	getLocalTimeAll (nS) {  //时间戳转换  xx-xx-xx
	   	return new Date(parseInt(nS)).toLocaleString().replace(/\//g,"-").replace(/[\u4e00-\u9fa5]/g,"");
	}
	updateDate(date,days){  //加减天数
		// console.log(date.days)
	    var d=new Date(date);
	    d.setDate(d.getDate()+days);
	    var m=d.getMonth()+1;
	    return d.getFullYear()+'-'+m+'-'+d.getDate();
	}

	changeDateFormat (date) { //xx-xx-xx  转  xx月xx日
		var arr = date.split('-');
		var month = arr[1],day = arr[2];

		if ((month == 0) && (day == 1)) return "元旦";
		else if ((month == 1) && (day ==15 )) return "除夕";
		else if ((month == 1) && (day ==16 )) return "春节";
		else if ((month == 2) && (day == 8)) return "妇女节";
		else if ((month == 2) && (day == 12)) return "植树节";

		else if ((month == 3) && (day == 1)) return "愚人节";
		else if ((month == 3) && (day == 5)) return "清明节";
		else if ((month == 4) && (day == 1)) return "劳动节";
		else if ((month == 4) && (day == 9)) return "母亲节";
		else if ((month == 5) && (day == 1)) return "儿童节";
		else if ((month == 5) && (day == 17)) return "父亲节";

		else if ((month == 7) && (day == 1)) return "建军节";
		else if ((month == 9) && (day == 1)) return "国庆节";

		else if ((month == 11) && (day == 24)) return "平安夜";
		else if ((month == 11) && (day == 25)) return "圣诞节";
		else return arr[1] + '月' + arr[2] + '日';

		/*[
			{time: '1-1', name: '元旦'},
			{time: '2-15', name: '除夕'},
			{time: '2-16', name: '春节'},
			{time: '3-8', name: '妇女节'},
			{time: '3-12', name: '植树节'},
			{time: '4-1', name: '愚人节'},
			{time: '4-5', name: '清明节'},
			{time: '5-1', name: '劳动节'},
			{time: '5-9', name: '母亲节'},
			{time: '6-1', name: '儿童节'},
			{time: '6-17', name: '父亲节'},
			{time: '8-1', name: '建军节'},
            {time: '10-1', name: '国庆节'},
			{time: '12-24', name: '平安夜'},
			{time: '12-25', name: '圣诞节'},
		]*/
		return '(' + arr[1] + '月' + arr[2] + '日)'
	}


	datestr (yy, mm, dd, prenext) { //求上下7天的日期
	    var s, d, t, t2;
	    t = Date.UTC(yy, mm, dd);
	    t2 = 7 * 1000 * 3600 * 24; //加减7天的时间
	    if (prenext == 'pre') {
	        t-= t2;
	    } else {
	        t+= t2;
	    }
	    d = new Date(t);
	    s = d.getUTCFullYear() + "-";
	    s += ("00"+(d.getUTCMonth()+1)).slice(-2) + "-";
	    s += ("00"+d.getUTCDate()).slice(-2);
	    this.form.time = s;
	}

	strdate(str, prenext){    //求上下7天的日期
	    var dd, mm, yy, arr;
	    var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
	    if (arr = str.match(reg)) {
	        yy = Number(arr[1]);
	        mm = Number(arr[2])-1;
	        dd = Number(arr[3]);
	    } else {
	        var d = new Date();
	        yy = d.getUTCFullYear();
	        mm = ("00"+(d.getUTCMonth())).slice(-2);
	        dd = ("00"+d.getUTCDate()).slice(-2);
	    }
	    if (prenext == null || (prenext != 'pre' && prenext != 'next')) {
	        var prenext = 'pre';
	    }
	    this.datestr(yy, mm, dd, prenext);
	}

	getHolidays (date) {
		console.log(date)
		var arr = date.split('-');

		var month = arr[1],day = arr[2];


		// return date
		// calendar = new Date();
		// month = calendar.getMonth();
		// date = calendar.getDate();

		if ((month == 0) && (day == 1)) return "元旦";
		else if ((month == 1) && (day ==13 )) return "除夕";
		else if ((month == 1) && (day ==14 )) return "春节/情人节";
		else if ((month == 2) && (day == 1)) return "国际海豹日";
		else if ((month == 2) && (day == 8)) return "国际劳动妇女节/中国保护母亲河日";
		else if ((month == 2) && (day == 12)) return "植树节";

		else if ((month == 3) && (day == 1)) return "愚人节";
		else if ((month == 3) && (day == 5)) return "清明节";
		else if ((month == 4) && (day == 1)) return "国际劳动节";
		else if ((month == 4) && (day == 9)) return "母亲节";

		else if ((month == 5) && (day == 1)) return "国际儿童节";
		else if ((month == 5) && (day == 26)) return "国际禁毒日";

		else if ((month == 7) && (day == 1)) return "建军节";
		else if ((month == 7) && (day == 15)) return "日本无条件投降日/世纪婚纱日";
		else if ((month == 7) && (day == 16)) return "七夕情人节";


		else if ((month == 9) && (day == 20)) return "世界厨师日";
		else if ((month == 9) && (day == 22)) return "世界传统医药日";
		else if ((month == 9) && (day == 24)) return "联合国日/世界发展信息日";
		else if ((month == 9) && (day == 25)) return "世界骨质疏松日/抗美援朝纪念日/环卫工人节";
		else if ((month == 9) && (day == 31)) return "世界勤俭日/中国男性健康日";

		else if ((month == 11) && (day == 24)) return "平安夜";
		else if ((month == 11) && (day == 25)) return "圣诞节";
		else return date;
	}

	getUrl (name) {
	    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	    var r = window.location.search.substr(1).match(reg);
	    if(r!=null)return  r[2]; return null;
	}


}
export default new Fn();
